package com.tengju.bff.interfaces.app.motivation;

import com.tengju.bff.interfaces.app.motivation.facade.BonusTopListFacade;
import com.tengju.bff.interfaces.app.motivation.vo.BonusRankDetailVO;
import com.tengju.bff.interfaces.app.motivation.vo.BonusRankVO;
import com.tengju.bff.interfaces.app.motivation.vo.PageBonusRankDetailVO;
import com.tengju.bff.interfaces.shared.ApiResponse;
import com.tengju.bff.interfaces.shared.servlet.NotTokenValid;
import com.tengju.bff.interfaces.shared.servlet.ServletContextUtil;
import com.tengju.bff.interfaces.shared.servlet.UserServletContext;
import com.tengju.user.domain.model.user.UserIdCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author chenhang
 * @Date 2021/7/19
 */
@Validated
@Slf4j
@RestController
@Api(tags = "收益排行榜")
@RequestMapping(value = "/app/bonus/topList")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class BonusTopListController {

    private final BonusTopListFacade bonusTopListFacade;

    @ApiOperation(value = "个人排名详情", notes = "个人排名详情")
    @RequestMapping(value = "rankInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ApiResponse<BonusRankVO> rankInfo() {
        UserServletContext servletContext = ServletContextUtil.getServletContext();
        UserIdCode userIdCode = servletContext.needIdCode();
        return ApiResponse.newSuccess(bonusTopListFacade.rankInfo(userIdCode));
    }

    @ApiOperation(value = "月度收益排行", notes = "月度收益排行")
    @RequestMapping(value = "monthRank", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ApiResponse<PageBonusRankDetailVO> monthRank(@RequestParam("month") Integer month,
                                                        @RequestParam("pageIndex") Integer pageIndex,
                                                        @RequestParam("pageSize") Integer pageSize) {

        return ApiResponse.newSuccess(bonusTopListFacade.monthRank(month,pageIndex,pageSize));
    }

    @ApiOperation(value = "年度收益排行", notes = "年度收益排行")
    @RequestMapping(value = "yearRank", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ApiResponse<PageBonusRankDetailVO> yearRank(@RequestParam("year") Integer year,
                                                       @RequestParam("pageIndex") Integer pageIndex,
                                                       @RequestParam("pageSize") Integer pageSize) {

        return ApiResponse.newSuccess(bonusTopListFacade.yearRank(year,pageIndex,pageSize));
    }

    @ApiOperation(value = "个人年度收益排行", notes = "个人年度收益排行")
    @RequestMapping(value = "selfYearRankDetail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ApiResponse<BonusRankDetailVO> selfYearRankDetail(@RequestParam("year") Integer year) {
        UserServletContext servletContext = ServletContextUtil.getServletContext();
        UserIdCode userIdCode = servletContext.needIdCode();
        return ApiResponse.newSuccess(bonusTopListFacade.selfYearRankDetail(userIdCode,year));
    }

    @ApiOperation(value = "个人月度收益排行", notes = "个人月度收益排行")
    @RequestMapping(value = "selfMonthRankDetail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ApiResponse<BonusRankDetailVO> selfMonthRankDetail(@RequestParam("month") Integer month) {
        UserServletContext servletContext = ServletContextUtil.getServletContext();
        UserIdCode userIdCode = servletContext.needIdCode();
        return ApiResponse.newSuccess(bonusTopListFacade.selfMonthRankDetail(userIdCode,month));
    }


}
